package demo1;

class Animal {
    public String name;
    public int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void eat() {
        System.out.println(age + "岁" + name + "在吃饭....");
    }
}

class Dog extends Animal {
    public Dog(String name, int age) {
        super(name, age);
    }

    public void eat() {
        System.out.println(age + "岁的" + name + "在狗粮....");
    }

    public void Brak() {
        System.out.println(name + "在汪汪叫....");
    }
}

class Brid extends Animal {
    public Brid(String name, int age) {
        super(name, age);
    }

    @Override
    public void eat() {
        System.out.println(age + "岁的" + name + "在鸟粮....");
    }
}

//多态的三种使用方法
//1.直接赋值使用
//2.通过方法进行调用
//3.通过返回值进行引用

public class Test {

    public static void func1(Animal animal) {
        animal.eat();
    }

    /*public static Animal func2() {
        Dog dog = new Dog("小黑", 4);
        return dog;
    }*/

    public static Animal func2(){
        Dog dog = new Dog("小黑",4);
        return dog;
    }

    public static void main(String[] args) {


        Animal animal1 = new Dog("小黄", 1);
        Animal animal2 = new Brid("小鸟", 3);
        func1(animal1);
        func1(animal2);
        Animal animal3=func2();
        animal3.eat();
        //Animal animal3=new Animal("小明",1);
        /*animal1.eat();
        animal2.eat();
        animal3.eat();*/
        //animal1.Brak();  父类中没有写这个方法，无法调用
    }


}
